extends ../layout

block css
    link(rel='stylesheet', href='/css/base/ck_base.css', media='screen')
    link(rel='stylesheet', href='/css/user/ck_user2.css', media='screen')
    link(rel='stylesheet', href='/css/modules/page.css')

block content

    .pageContainer.pt20.mb20
      #studentMenu.pageSidebar
        .wsxx
          .hd
            dl
              dt(clas='pic')
                a(href='#', target='_blank')
                  img(width='40', height='40', title='背后灵16', src='/images/0-0.JPG')
              dd
                .name
                  a.c_666(href='#', target='_blank') 背后灵16
                .set
                  a(href='#', target='_blank') 设置
          .bd
            ul.list
              li.wsxx_2.myCourse
                a.myCourse(href='/user/course') 我的课程
              li.wsxx_4.myTask
                a.myTask(href='/user/work') 我的作业
              li.wsxx_5.myTest
                a.myTest(href='/user/quiz') 我的测验
              li.wsxx_12
                a(href='/user/note') 我的笔记
              li.wsxx_13.curr
                a(href='/user/question') 我的问答
              li.wsxx_9
                a(href='/user/order') 我的订单
              li.wsxx_10.myRefund
                a(href='/user/apply') 退款管理
        // =E wsxx 侧边导航
      .pageContent
        .mcTitle.clearfix
          ul.user_tab1.fl
            if type === 1
              li.curr
                a(href='/user/question?type=1') 我问的
              li
                a(href='/user/question?type=2') 我答的 
            else
              li
                a(href='/user/question?type=1') 我问的
              li.curr
                a(href='/user/question?type=2') 我答的              
            // 问答的展示形式相同
        section.my_qa
          ul.qa_list
            if list
              each val in list
                li.clearfix
                  .label
                    p.label_num #{val.answer.length}
                    p.label_txt 已回答
                  .text
                    p.p1.c_555.f14 #{val.question.content}
                    p.p2.c_999
                      span.mr30.f12
                        | 课程：
                        a(href='#') #{val.question.course}
                      //span.ml30 答复时间：#{val.question.time}
                    .text_child(id='answerlist_#{val.question.id}',style='width: 770px; display: none;')
                      if val.answer
                        each ans in val.answer
                          .text_sub.clearfix(style='width:770px;')
                            .text_sub_t
                              span.c_555.mr10.ter #{ans.name}
                            .text_sub_b #{ans.content}
                            .text_sub_f 
                              span.mr20 #{ans.time}
             
                  a.plode_down(href='javascript:;', qid='#{val.question.id}') 答案
          include ../common/page.jade  

      // =E pageContent
      s.clearfix
    script.
      $(function () {
      $(".plode_down").live('click', function () {
      var cobj = $(this);
      var qid = cobj.attr('qid');
      $("#answerlist_" + qid).slideDown(500);
      cobj.removeClass('plode_down').addClass('plode_up').text('收起');
      });
      $(".plode_up").live('click', function () {
      var cobj = $(this);
      var qid = cobj.attr('qid');
      $("#answerlist_" + qid).hide();
      cobj.removeClass('plode_up').addClass('plode_down').text('答案');
      });
      $("#nextpage").click(function () {
      var cobj = $(this);
      var page = cobj.attr('page');
      page = parseInt(page) + 1;
      $.ajax({
      url: "/?mod=faq&act=student&do=answerlist&page=" + page + "&type=data&random=" + Math.random(),
      type: "get",
      dataType: "json",
      beforeSend: function () {
      $("#pagelist").hide();
      $("#loadingbar").show();
      },
      success: function (ret) {
      if (ret.length > 0) {
      var str = '';
      $.each(ret, function (i, v) {
      str += '<li class="clearfix">';
      str += '<div class="label">';
      str += '<p class="label_num">' + v.Answers + '</p>';
      str += '<p class="label_txt">已回答</p>';
      str += '</div>';
      str += '<div class="text">';
      str += '<p class="p1 c_555 f14">' + v.Question + '</p>';
      str += '<p class="p2 c_999">';
      str += '<span class="mr30 f12">课程：<a target="_blank" href="' + v.CourseUrl + '">' + v.CourseName + '</a></span>';
      str += '<span class="ml30">答复时间：' + v.CreateTime + '</span>';
      str += '</p>';
      str += '<div class="text_child" style="display:none;width:770px;" id="answerlist_' + v.QID + '">';
      $.each(v.AnswerList, function (k, answer) {
      str += '<div class="text_sub clearfix" style="width:770px;">';
      str += '<div class="text_sub_t">';
      str += '<span class="c_555 mr10 ter">' + answer.NickName + '</span>';
      if (answer.IsTeacher == 1) {
      str += '<span class="tch">老师已答</span>';
      }
      str += '</div>';
      str += '<div class="text_sub_b">' + answer.Answer + '</div>';
      str += '<div class="text_sub_f">';
      str += '<span class="mr20">' + answer.CreateTime + '</span>';
      str += '<span class="ml5 fav">感谢<em class="c_1cb177">（' + answer.Thanks + '）</em></span>';
      str += '</div></div>';
      });
      str += '</div></div>';
      str += '<a href="javascript:;" class="plode_down" qid="' + v.QID + '">答案</a>';
      str += '</li>';
      });
      $("#pagelist").before(str);
      $("#nextpage").attr('page', page);
      } else {
      $("#pagelist").html('<p class="c_777">没有更多问题了</p>');
      }
      $("#loadingbar").hide();
      $("#pagelist").show();
      }
      });
      return false;
      });
      });
      function answer_thank(qid, ruid, sid) {
      $.ajax({
      url: "/?mod=faq&act=student&do=thanks",
      type: "post",
      dataType: "json",
      data: "qid=" + qid + "&ruid=" + ruid + "&sid=" + sid,
      success: function (ret) {
      if (ret.code == 0) {
      var thankid = '#thank_' + qid + ruid;
      //             	var heartid = '#heart_'+qid+ruid;
      var num = parseInt($(thankid).text()) + 1;
      $(thankid).text(num);
      //             	$(heartid).addClass('thanked');
      } else {
      var already = '#already_thanks_' + qid + ruid;
      $(already).fadeIn(500);
      $(already).fadeOut(3000);
      }
      }
      });
      }
